package Demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 殇
 * Date: 2025-06-04
 * Time: 16:06
 */
public class Dog extends Animal{
    public Dog(String name){
        super(name);
        this.name=name;
    }

    public void bark(){
        System.out.println(name+"正在叫...");
    }

    public  static void fun1(Animal animal){    //这里需要加static，这样就不依赖于对象，可以直接调用
        animal.eat();
        //animal.bark("小白");  报错，animal虽然指向dog类，但其本身可访问的成员由自身的类型决定
    }

    public static Animal fun2(){
        Dog dog=new Dog("小黑");
        return dog;
        // (Animal)dog
    }



    public static void main1(String[] args) {
        //父类引用指向了子类对象
        Animal animal=new Dog("旺财");
        //参数传递
        Cat cat=new Cat("小白");
        Dog dog=new Dog("小黑");
        fun1(dog);    //Animal animal =dog    本质还是父类引用指向了子类对象
        fun1(cat);    //Animal animal =cat

        //返回值传递
        fun2();
    }
}
